package com.iretailer.report.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.iretailer.report.util.NumberUtil;
import com.iretailer.report.util.StringUtil;
import com.iretailer.report.util.TimeUtilOld;
import lombok.Data;

import java.util.List;
import java.util.Map;


/**
 * @Auther xjw
 * @Date 2019/1/21 1026
 * @Description
 */
@Data
public class GlobalReportModel {

    public GlobalReportModel() {
    }

    public static GlobalReportModel getMallIdInit(String domainLabel, String mallId, int clerk, int acreage, int ranked) {
        GlobalReportModel result = new GlobalReportModel();
        result.setDomainLabel(domainLabel);
        result.setMallId(mallId);
        result.setEnter(0);
        result.setExit(0);
        result.setClerk(clerk);
        result.setAcreage(acreage);
        result.setRanked(ranked);
        return result;
    }

    public static GlobalReportModel getPhyIdInit(String domainLabel, String mallId, String phyId, int ranked) {
        GlobalReportModel result = new GlobalReportModel();
        result.setDomainLabel(domainLabel);
        result.setMallId(mallId);
        result.setPhyId(phyId);
        result.setEnter(0);
        result.setExit(0);
        result.setRanked(ranked);
        return result;
    }

    public static GlobalReportModel getDeviceInit(String domainLabel, String mallId, String deviecId, int ranked) {
        GlobalReportModel result = new GlobalReportModel();
        result.setDomainLabel(domainLabel);
        result.setMallId(mallId);
        result.setDeviceId(deviecId);
        result.setAlarmTimes(0);
        result.setRanked(ranked);
        return result;
    }


    public static GlobalReportModel getTagTypeInit(String domainLabel, String firstMallId, int clerk, int acreage, int ranked, String tagTypeId, List<String> mallIds) {
        GlobalReportModel result = new GlobalReportModel();
        result.setTagTypeId(tagTypeId);
        result.setDomainLabel(domainLabel);
        result.setEnter(0);
        result.setExit(0);
        result.setRanked(ranked);
        result.setClerk(clerk);
        result.setAcreage(acreage);
        result.setMallId(firstMallId);
        result.setMallIds(mallIds);
        return result;
    }

    public static GlobalReportModel getDomainLabelInit(String domainLabel, String firstMallId, int clerk, int acreage, int ranked) {
        GlobalReportModel result = new GlobalReportModel();
        result.setDomainLabel(domainLabel);
        result.setEnter(0);
        result.setExit(0);
        result.setRanked(ranked);
        result.setClerk(clerk);
        result.setAcreage(acreage);
        result.setMallId(firstMallId);
        return result;
    }

    /**
     * 用于 区域，tag，案场,设备排序
     */
    @JSONField(name = "Ranked")
    private int ranked;

    @JSONField(name = "DomainLabel")
    private String domainLabel;


    @JSONField(name = "TimeLabel")
    private String timeLabel;

    @JSONField(name = "TimeFormatter")
    private String timeFormatter;

    @JSONField(name = "DateTime")
    private String dateTime;

    @JSONField(serialize = false)
    private String date;

    // 案场Id集合 用于 Tag
    private List<String> mallIds;

    @JSONField(name = "TagTypeId")
    private String tagTypeId;

    //案场Id
    @JSONField(name = "MallId")
    private String mallId;

    //区域Id
    @JSONField(name = "PhyId")
    private String phyId;

    // 设备Id
    @JSONField(name = "DeviceId")
    private String deviceId;

    // 进入客流
    @JSONField(name = "Enter")
    private int enter;

    //离开客流
    @JSONField(name = "Exit")
    private int exit;

    // 停留人数
    @JSONField(name = "Stay")
    private int stay;

    //经过客流
    @JSONField(name = "Passby")
    private int passBy;

    //入店率
    @JSONField(name = "EnteringRate")
    private double enteringRate;

    // Dwell
    @JSONField(name = "EntranceCount")
    private int entranceCount;

    @JSONField(name = "PassCount")
    private int passCount;

    @JSONField(name = "StayCount")
    private int stayCount;

    @JSONField(name = "SecondsCount")
    private int secondsCount;

    //展示率
    @JSONField(name = "DisplayRate")
    private double displayRate;


    //吸引率
    @JSONField(name = "AttractionRate")
    private double attractionRate;

    // 平均停留时长
    @JSONField(name = "AverageStay")
    private double averageStay;


    //试衣人数
    @JSONField(name = "Fitting")
    private int fitting;

    //试衣率
    @JSONField(name = "FittingRate")
    private double fittingRate;


    //销售额
    @JSONField(name = "Sales")
    private double sales;

    //交易数
    @JSONField(name = "Receipts")
    private double receipts;

    //交易件数
    @JSONField(name = "Pieces")
    private double pieces;

    //转化率 receipts/enter
    @JSONField(name = "ConvertRate")
    private double convertRate;


    //客单价   sales/enter
    @JSONField(name = "PricePerCustomer")
    private double pricePerCustomer;


    //客件数  pieces/enter
    @JSONField(name = "PiecePerCustomer")
    private double piecePerCustomer;


    //票单价  sales/receipts
    @JSONField(name = "PricePerReceipt")
    private double pricePerReceipt;


    //票件数 pieces/receipts
    @JSONField(name = "PiecePerReceipt")
    private double piecePerReceipt;


    //件单价  sales/pieces
    @JSONField(name = "PricePerPiece")
    private double pricePerPiece;

    //店员
    @JSONField(name = "Clerk")
    private int clerk;

    //顾客员工比 enter/clerk
    @JSONField(name = "ClerkRatio")
    private double clerkRatio;


    //面积
    @JSONField(name = "Acreage")
    private double acreage;

    // 集客力 enter/acreage
    @JSONField(name = "AcreageRatio")
    private double acreageRatio;


    // 天气
    @JSONField(name = "HighTemp")
    private int highTemp;

    @JSONField(name = "LowTemp")
    private int lowTemp;

    @JSONField(name = "TempUnit")
    private String tempUnit;

    @JSONField(name = "Temp")
    private String temp;

    @JSONField(name = "Pm25")
    private double pm25;

    @JSONField(name = "WeatherName")
    private String weatherName;

    @JSONField(name = "DayPictureUrl")
    private String dayPictureUrl;

    @JSONField(name = "NightPictureUrl")
    private String nightPictureUrl;

    //活动节假日
    @JSONField(name = "ActivityName")
    private String activityName;

    @JSONField(name = "Male")
    private int male;

    @JSONField(name = "Female")
    private int female;

    @JSONField(name = "AgeRatio")
    private Map<String, Integer> ageRatio;

    @JSONField(name = "AgeTypes")
    private List<String> ageTypes;

    @JSONField(name = "AlarmTimes")
    private int alarmTimes;


//    public Integer getStay() {
//        return Math.abs(enter - exit);
//        return enter - exit;
//    }


    public double getPiecePerReceipt() {
        if (this.receipts > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(this.pieces / this.receipts));
        } else {
            return 0d;
        }
    }

    public double getAcreageRatio() {
        if (this.acreage > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format((double) this.enter / this.acreage));
        } else {
            return 0d;
        }
    }

    public String getTemp() {
        if (!StringUtil.notEmpty(tempUnit)) {
            tempUnit = "℃";
        }
        return highTemp + "~" + lowTemp + tempUnit;
    }

    public String getDateTime() {
        if (timeLabel != null) {
            if ("Week".equals(this.timeFormatter)) {
                this.timeFormatter = "yyyy-MM-dd";
            }
            switch (this.timeLabel) {
                case "All":
                    return this.timeLabel;
                case "Tue":
                case "Wed":
                case "Thu":
                case "Fri":
                case "Sat":
                case "Sun":
                case "Mon":
//                    return TimeUtilOld.getDateTime(TimeUtilOld.getDateOfString(this.timeLabel));
                    return this.timeLabel;
                default:
                    return TimeUtilOld.getDateTime(TimeUtilOld.getDateOfString(this.timeLabel, this.timeFormatter));
            }
        } else {
            return null;
        }
    }

    public double getClerkRatio() {
        if (this.clerk > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format((double) this.enter / this.clerk));
        } else {
            return 0d;
        }
    }

    public String getDate() {
        if (timeLabel != null) {
            switch (this.timeFormatter) {
                case "Week":
                    this.timeFormatter = "yyyy-MM-dd";
                    break;
                case "WeekPeak":
                case "MonthPeak":
                case "YearPeak":
                    this.timeFormatter = "yyyy-MM-dd HH:mm";
                    break;
            }
            switch (this.timeLabel) {
                case "All":
                case "Tue":
                case "Wed":
                case "Thu":
                case "Fri":
                case "Sat":
                case "Sun":
                case "Mon":
                    return this.timeLabel;
                default:
                    return TimeUtilOld.getDate(TimeUtilOld.getDateOfString(this.timeLabel, this.timeFormatter));
            }
        } else {
            return null;
        }
    }


    public double getPricePerPiece() {
        if (this.pieces > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(this.sales / this.pieces));
        } else {
            return 0d;
        }
    }

    public double getEnteringRate() {
//        double total = this.enter + this.passBy;
        if (this.passBy > 0) {
            double pb = this.enter / ((double) (this.passBy + this.enter)) * 100;
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(pb));
        } else {
            return 0.0;
        }
    }

    public double getDisplayRate() {
        if (this.entranceCount > 0) {
            return Double.valueOf(NumberUtil.get2DecimalFormat().format((double) this.passCount / this.entranceCount * 100));
        } else {
            return 0.0;
        }
    }

    public double getAttractionRate() {
        if (this.passCount > 0) {
            return Double.valueOf(NumberUtil.get2DecimalFormat().format((double) this.stayCount / this.passCount * 100));
        } else {
            return 0.0;
        }
    }

    public double getAverageStay() {
        if (this.stayCount > 0) {
            return Math.round((double) this.secondsCount / this.stayCount);
        } else {
            return 0;
        }
    }

    public double getFittingRate() {
        if (this.enter > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format((double) this.fitting / this.enter));
        } else {
            return 0d;
        }
    }

    public double getConvertRate() {
        if (this.enter > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(this.receipts / this.enter));
        } else {
            return 0d;
        }
    }

    public double getPricePerCustomer() {
        if (this.enter > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(this.sales / this.enter));
        } else {
            return 0d;
        }
    }

    public double getPiecePerCustomer() {
        if (this.enter > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(this.pieces / this.enter));
        } else {
            return 0d;
        }
    }

    public double getPricePerReceipt() {
        if (this.receipts > 0) {
            return Double.parseDouble(NumberUtil.get2DecimalFormat().format(this.sales / this.receipts));
        } else {
            return 0d;
        }
    }
}
